﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class CampusManagerUserRepository : UserRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<CampusManagerUser> FindAllCampusManagerUsers()
        {
            return db.CampusManagerUsers;
        }

        public CampusManagerUser GetCampusManagerUserById(int id)
        {
            return db.CampusManagerUsers.SingleOrDefault(cmu => cmu.UserIdFK == id);
        }

        //Insert/Delete Methods

        public void Add(CampusManagerUser campusManagerUser)
        {
            int uId = new UserRepository().Add2((User)campusManagerUser);
            campusManagerUser.UserIdFK = uId;
            db.CampusManagerUsers.InsertOnSubmit(campusManagerUser);
        }

        public void Delete(CampusManagerUser campusManagerUser)
        {
            db.CampusManagerUsers.DeleteOnSubmit(campusManagerUser);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}